package com.mdxx.xczd.ui.activity;

import android.content.pm.PackageManager;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.mdxx.xczd.R;
import com.mdxx.xczd.app.App;
import com.mdxx.xczd.ui.base.BaseActivity;
import com.mdxx.xczd.utils.ToastUtil;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by MD-02 on 2017/1/16.
 */

public class MoreActivity extends BaseActivity {

    @BindView(R.id.ll_lognout)
    LinearLayout mLinLognout;

    @BindView(R.id.tv_versioninfo)
    TextView mTvVersion;

    @BindView(R.id.btn_back)
    ImageButton mBtnBack;

    @Override
    protected int getLayout() {
        return R.layout.activity_more;
    }

    @Override
    protected void init() {
        getVersionInfo();
    }

    @Override
    public void initPresenter() {

    }

    @OnClick({R.id.ll_lognout, R.id.btn_back})
    void onClick(View v) {

        switch (v.getId()) {
            case R.id.ll_lognout:
                lognout();
                break;

            case R.id.btn_back:
                onBackPressed();
                break;

            default:
                break;
        }
    }

    /**
     * 版本名
     */
    private void getVersionInfo(){
        try {
            String versionName= getPackageManager().getPackageInfo(getPackageName(),0).versionName;
            mTvVersion.setText("V"+versionName);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    /**
     * 登出
     */
    private void lognout(){
        App.cancelAccount();
        ToastUtil.showShort("登出成功");
        removeAll();
        startActivity(LoginActivity.class);
    }
}
